﻿using SvGame.Objects;

namespace SvGame.Logic;

public static partial class GameLogic
{
    public static bool NewNpc(ConfigNpcExt confExt, out Npc obj)
    {
        var conf = confExt.SettBase;
        obj = new()
        {
            Uid = IdMgr.CreateObjectId(),
            ConfigId = conf.Id,
            Cfg = confExt,
        };
        obj.Age = conf.Age.RandomRange();
        obj.Exp = conf.Exp.RandomRange();
        obj.Gold = conf.Gold.RandomRange();
        obj.Gem = conf.Gem.RandomRange();

        if (conf.Hp.Count >= 4)
        {
            obj.StatusMax.Kee = conf.Hp[0];
            obj.StatusMax.Sen = conf.Hp[1];
            obj.StatusMax.Force = conf.Hp[2];
            obj.StatusMax.Mana = conf.Hp[3];
        }
        obj.StatusEff = obj.StatusMax.Clone();
        obj.StatusCur = obj.StatusMax.Clone();

        if (conf.Talent.Count >= 8)
        {
            obj.Talent.Str = conf.Talent[0];
            obj.Talent.Int = conf.Talent[1];
            obj.Talent.Con = conf.Talent[2];
            obj.Talent.Spi = conf.Talent[3];
            obj.Talent.Cps = conf.Talent[4];
            obj.Talent.Cor = conf.Talent[5];
            obj.Talent.Per = conf.Talent[6];
            obj.Talent.Kar = conf.Talent[7];
        }

        obj.ActionSet();

        return true;
    }
    public static NpcInfo GetInfo(this Npc obj)
    {
        var info = new NpcInfo();
        info.Uid = obj.Uid;
        info.ConfigId = obj.ConfigId;
        info.Age = obj.Age;
        info.Exp = obj.Exp;
        info.Per = obj.Talent.Per;
        info.InfoStatus = obj.InfoStatus();
        return info;
    }
}
